package com.colin.job.executor.handler;

import com.alibaba.fastjson.JSONObject;
import com.colin.dubbo.business.request.Demo1Request;
import com.colin.dubbo.business.request.Demo2Request;
import com.colin.dubbo.business.response.CommonResponse;
import com.colin.dubbo.enums.MethodEnum;
import com.colin.dubbo.service.BaseService;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import javax.annotation.Resource;
import org.springframework.stereotype.Component;

@Component
public class DemoJob {
    
    @Resource
    private BaseService baseService;

    @XxlJob("demo1Job")
    public void demoJobHandler() throws Exception {
        Demo1Request request = new Demo1Request();
        request.setMethod(MethodEnum.DEMO1);
        request.setDemo1("demo1");

        XxlJobHelper.log("demo1 request:" + JSONObject.toJSONString(request));
        CommonResponse handle = baseService.handle(request);
        XxlJobHelper.log("demo1 response:" + JSONObject.toJSONString(handle));
    }

    @XxlJob("demo2Job")
    public void demo2Handler() throws Exception {
        Demo2Request request = new Demo2Request();
        request.setMethod(MethodEnum.DEMO2);
        request.setDemo2("demo2");

        XxlJobHelper.log("demo2 request:" + JSONObject.toJSONString(request));
        CommonResponse handle = baseService.handle(request);
        XxlJobHelper.log("demo2 response:" + JSONObject.toJSONString(handle));
    }
}
